package org.lc.design.samples.case2.builder;

import lombok.extern.slf4j.Slf4j;
import org.lc.design.samples.case2.item.Item;
import org.lc.design.samples.case2.item.burger.ItemBurger;
import org.lc.design.samples.case2.item.drinks.ItemDrink;
import org.lc.design.samples.case2.item.snacks.ItemSnack;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class ItemBuilder {

    List<Item> items = new ArrayList<>();

    // 套餐等级
    private Integer packageLevel;

    public ItemBuilder appendPackageLevel(Integer packageLevel) {
        this.packageLevel = packageLevel;
        return this;
    }

    public ItemBuilder appendBurger(ItemBurger burger) {
        items.add(burger);
        return this;
    }

    public ItemBuilder appendDrink(ItemDrink drink) {
        items.add(drink);
        return this;
    }

    public ItemBuilder appendSnack(ItemSnack snack) {
        items.add(snack);
        return this;
    }

    public void showItems() {
        float price = 0.0f;
        log.info("付款单");
        log.info("选购套餐：套餐{}", packageLevel);
        log.info("食物清单：");
        for (Item item : items) {
            log.info("{}：{}元", item.name(), item.price());
            price += item.price();
        }
        log.info("总额：{}", price);
    }
}
